Skip to content

driver/memcached: compare the least of several interleaved rounds in the per-operation limit alloc test - #1237

Merged
FumingPower3925 merged 4 commits into
mainfrom
fix/test-alloc-compare-1235
Nov 3, 2026
Merged

FumingPower3925 merged 4 commits into
mainfrom
fix/test-alloc-compare-1235

Conversation

@FumingPower3925

@FumingPower3925 FumingPower3925 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1235

TestOperationLimitDoesNotAllocate1218/eventloop failed on the Coverage job (-race): 4.0 allocs/op with the limit, 3.0 without.

Reproduced (Linux, golang:1.27.3, 2 CPUs, go test -race -run TestOperationLimitDoesNotAllocate1218)

  • -count=200: 3 failed subtests in 2 runs (direct, eventloop, netconn).
  • -count=1000: 10 failed runs of 1000 (5 direct, 2 eventloop, 3 netconn of 3000 subtests). The rounds that came out one above their cost went both ways (10 times 4.0 with, 3.0 without, 22 times 3.0 with, 4.0 without), so the limit costs nothing and the noise is sync.Pool's.

Change

The two clients are built and warmed first, then measured in turns over 7 rounds of 100 runs, and the test compares the least of the rounds of each side (onMin > offMin fails). Per-round measure under -race (12 rounds x 89 runs x 3 clients): a round ends at 4 instead of 3 about once in 35 rounds, never at 5, on either side alike. The noise only adds allocations, so the least of the rounds is the cost of a side; with 7 rounds all of one side's rounds would have to be inflated (about 1e-11). The side measured first alternates from round to round. A limit that costs a whole allocation or more on every command raises every round of its side and so its least, and fails the test. AllocsPerRun rounds its average down, so a limit that allocates on only some of the commands (under 1 per command on average) is not seen, in plain mode or under -race; the single round this replaces did not see it reliably either (only by the same pool noise that made it flaky). The strict budget TestAllocBudgets is untouched, and no !race tag is added, so ci.yml is unchanged.

Mutant

beginOp allocates one object per command when the limit is on (mutSink = new([16]byte)): 4.0 allocs/op with the limit, 3.0 without in 60 of 60 subtests (20 runs x 3 clients), red under -race and plain, with the alternating order as well.

After

  • -race -count=500: 0 failures (1500 subtests, all 3.0 with, 3.0 without); plain -count=200: 0 (600 subtests). (The first version of this PR: -race -count=1000 0 failures, against 10 failed runs of 1000 before.)
  • go test -race ./driver/memcached ok; GOOS=windows and GOOS=darwin go vet ./driver/... ok; golangci-lint 0 issues on ./driver/memcached/....

Siblings

No other comparison test in #1222 or #1227 counts allocations: alloc_guard_test.go (#1222) is an absolute budget under !race; the #1227 tests are about socket options. TestRefreshForMovedAllocatesNothingWhenNothingFailed1214 in driver/redis asserts an absolute 0 on code that uses no pool.

…TestOperationLimitDoesNotAllocate1218

The test measured the client with the per-operation limit and the one without it
one after the other, one AllocsPerRun of 200 runs each, and failed when the first
came out above the second. Under -race sync.Pool drops Puts at random, so a round
of either side can end an allocation above its true cost (1 round in 35 on 2
CPUs), and with one round per side the Coverage job saw "4.0 allocs/op with the
limit, 3.0 without" (10 failed runs of 1000 under -race before).

Both clients are built and warmed first and measured in turns over 7 rounds of 100
runs, and the test compares the least of the rounds of each side. The noise only
adds allocations, so the least is the cost; a limit that allocates raises every
round of its side. The plain budget (TestAllocBudgets) stays the guard.

Refs #1235
@FumingPower3925 FumingPower3925 added this to the v1.6.0 milestone Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

…nate the side measured first

The comparison sees a limit that costs a whole allocation or more on every command
(AllocsPerRun rounds its average down, so one that allocates on some commands only
is invisible, as it was to the single round); the comment says so. The side
measured first alternates from round to round.

Refs #1235
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@FumingPower3925
FumingPower3925 marked this pull request as ready for review November 3, 2026 06:18
@FumingPower3925
FumingPower3925 merged commit 14d38b3 into main Nov 3, 2026
56 checks passed
@FumingPower3925
FumingPower3925 deleted the fix/test-alloc-compare-1235 branch November 3, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant